<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css"/>
    <style>
        tr th {
            text-align: center !important;
            font-weight: bold !important;
        }

        tr td {
            text-align: center !important;
        }

        img {
            margin-left: 5px
        }


        .check-layer .layui-form-checkbox {
            margin-bottom: 20px;
            display: block
        }

        .check-layer .layer-container {
            height: 300px;
            overflow-x: hidden;
            overflow-y: scroll
        }


        .label-box .con-label {
            margin-left: 0;
            margin-right: 15px;
            margin-bottom: 10px
        }

    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding-top: 40px;">
            <form class="layui-form" id="newsAddForm" enctype="multipart/form-data">
                <%--隐藏用户id--%>
                <input class="idsInput" type="hidden" name="cidlist">
                <div class="layui-form-item">
                    <label class="layui-form-label">推送形式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="pushType" lay-filter="jiedian" value="single" title="单个/多个推送"
                               checked="">
                        <input type="radio" name="pushType" lay-filter="jiedian" value="all" title="全部推送">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>消息内容</label>
                    <div class="layui-col-sm7">
                        <textarea id="content" name="content" class="layui-textarea" maxlength="50"
                                  placeholder="请输入内容，字数控制在50内" style="width:1000px; height:20px;"></textarea>
                    </div>
                </div>
                <div class="layui-form-item cust_select">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>用户选择</label>
                    <button class="layui-btn showThis" type="button" style="margin-left: 10px" >点击选择</button>

                </div>
                <div class="layui-form-item buttonPush" style="display: none">
                    <div class="layui-footer" style="text-align:center ">
                        <button type="button" class="layui-btn" onclick="saveNews()">
                            <i class="layui-icon">&#xe681</i>推送站内信
                        </button>
                    </div>
                </div>
            </form>

            <script type="text/html" id="index">
                {{d.LAY_TABLE_INDEX+1}}
            </script>
            <script type="text/html" id="status">
                {{#  if(d.status == 1){ }}
                <span class="layui-badge layui-bg-green">正常</span>
                {{# }else{ }}
                <span class="layui-badge">冻结</span>
                {{# }}}
            </script>
            <script type="text/html" id="money">
                <span style="color: red">{{d.account.money.toFixed(2)}}</span>
            </script>
            <script type="text/html" id="point">
                {{d.account.point.toFixed(2)}}
            </script>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>

    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['form', 'layer', 'jquery', 'table'], function () {
        var table = layui.table, form = layui.form;

        form.on('radio(jiedian)', function (data) {
            var val = data.value;//判断单选框的选中值
            if (val == 'all') {
                $(".cust_select").hide();
                $(".buttonPush").show();
            } else {
                $(".cust_select").show();
                $(".buttonPush").hide();
            }
        });

        var active = {
            showThis: function(content, url) {
                window.location.href = url + "?content=" + content;
            }
        };

        var type = 'showThis';
        $('.showThis').on('click', function(){
            var url = '/news/pushCustomer';
            var pushType = layui.$("input[name='pushType']").val();
            var content = layui.$('#content').val();
            if(pushType == 'single'){
                if(content == null || content == ''){
                    alert("请输入推送内容");
                }else {
                    active[type] && active[type].call(this, content, url);
                }
            }
        });

    });

    function saveNews() {
        $("#newsAddForm").ajaxSubmit({
            type: 'post',
            url: "/news/handlePush",
            data: $("#newsAddForm").serialize(),
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    layer.msg(data.desc);
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000)
                } else {
                    layer.msg(data.desc);
                }
            },
            error: function () {
                layer.msg("请检查页面信息是否正确");
            }
        });
    }

</script>
</body>
</html>